//
//  SettingPayPasswordViewModel.swift
//  Exchange
//
//  Created by rui on 2018/6/7.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class SettingPayPasswordViewModel: BaseViewModel {
    var payPassword: String = ""
    
    var mobileCode: String = ""
    
    var mobile: String = ""
        
    lazy var capitalRequest: CapitalRequest = {
        let api = CapitalRequest()
        api.dataReformer = self
        api.paramSource = self
        api.delegate = self
        return api
    }()
    
    func settingPayPwd(payPassword: String) {
        self.payPassword = payPassword
        self.capitalRequest.loadData()
    }
    
}

extension SettingPayPasswordViewModel:RequestCallBack,RequestDataReformer,RequestParamSource {
    
    func reform(_ request: BaseRequest, _ data: [String : Any]?) {
        if let _ = request as? CapitalRequest {
            self.response?(ResponseState.mine_payPwd,true, nil)
        }
    }
    
    func requestDidSucess(_ request: BaseRequest) {
        
    }
    
    func requestDidFail(_ request: BaseRequest) {
        if let _ = request as? CapitalRequest {
            self.response?(ResponseState.mine_payPwd,false, request.errorMsg)
        }
    }
    
    func requestParams(_ request: BaseRequest) -> [String : Any]? {
        var pramas: [String:Any] = [:]
        if let _ = request as? CapitalRequest {
            pramas.updateValue(2, forKey: "codeType")
            pramas.updateValue(payPassword, forKey: "password")
            pramas.updateValue(mobile, forKey: "mobile")
            pramas.updateValue(mobileCode, forKey: "mobileCode")
            pramas.updateValue(0, forKey: "type")
        }
        return pramas
    }
}
